/**
 * Created with JetBrains WebStorm.
 * User: Administrator
 * Date: 13-11-10
 * Time: 下午1:08
 * To change this template use File | Settings | File Templates.
 */
Ext.define("byb.view.BaseManager",{
    extend:"Ext.Panel",
    alias:"widget.baseManager",
    border:false,
    ui:'byb',
    cls:"BaseManager",
    layout:"border",
    initComponent:function(){
        this.items=[{xtype:"panel",region:"north",items:[this.buildQueryView()]},this.buildGridView()];
        this.listeners={
            afterrender:this.doDataLoad
        };
        this.callParent(arguments);
    },
    buildQueryView:function(){
        return {};
    },
    buildGridView:function(){
        return {};
    },
    getComboBoxStoreByType:function(params){
        return Ext.create("byb.store.DictStore",params);
    },
    doDataLoad:function(){

    },
    queryWidgetByName:function(name){
        var widget= Ext.ComponentQuery.query(name)[0];
        return widget;
    },
    q: function(name){
        return this.queryWidgetByName(name);
    },
    /**
     * 传入combo控件 查询出combo显示的值
     * @param combo 想要查询的combo控件
     * @param valueName 可选 默认为 id
     * @param displayName 可选 默认为 name
     */
    getComboText : function(combo, valueName, displayName){
    	var value = combo.getValue();
    	if (!value) {
    		return null;
    	}
    	
    	var valueField = 'id';
    	if (valueName) {
    		valueField = valueName;
    	}
    	var displayField = 'name';
    	if (displayName) {
    		displayField = displayName;
    	}
    	
    	var store = combo.getStore();
    	for ( var i = 0; i < store.getCount(); i++) {
    		var rawData = store.getAt(i).data;
    		if (rawData) {
    			if (rawData[valueField] == value) {
    				return rawData[displayField];
    			}
    		}
		}
    }
});